#!/bin/sh

#   COPYRIGHT 2003-2006, EMULEX CORPORATION                               
#   3333 Susan St., Costa Mesa, CA 92626                                  
#                                                                         
#   All rights reserved.  This computer program and related documentation 
#   is protected by copyright  and distributed under licenses restricting 
#   its use,  copying,  distribution  and decompilation.    This computer 
#   program  and its  documentation  are CONFIDENTIAL  and a TRADE SECRET 
#   of EMULEX CORPORATION.   The receipt or  possession of  this  program 
#   or its documentation does not  convey rights to reproduce or disclose 
#   its  contents,  or to  manufacture, use, or sell anything that it may 
#   describe, in whole or in part,  without the specific  written consent 
#   of  EMULEX CORPORATION.   Any reproduction  of  this program  without 
#   the express  written  consent  of EMULEX  CORPORATION  is a violation 
#   of the  copyright laws  and may  subject you to  criminal prosecution.

opt="$1"

SSCInstall=0
kernelInstall=0
LOGFILE="/usr/src/lpfcdfc/utils-install.log"
libnl_warning=0

# Function:  log_message()
#
# Description:
#   Print the strings passed as parameters to both STDOUT as well as
#   to a log file.
#
# Parameters:
#   A series of strings.
#
# Returns:
#   0 on success.
log_message()
{
    local ECHO_OPTIONS
    LOGDIRECTORY=${LOGFILE%/*}
    if [ ! -d ${LOGDIRECTORY} ] ; then
	mkdir -p ${LOGDIRECTORY}
    fi

    if [ $# -eq 0 ] ; then
	echo "" | tee -a ${LOGFILE}
    elif [ -z "$1" ] ; then
	echo "" | tee -a ${LOGFILE}
    elif [ "$1" = "-init" ] ; then
	echo "$0 - $(date)" >> ${LOGFILE}
    else
	while [ -n "$1" ] ; do
	    if [ "${1:0:1}" = "-" ] ; then
		ECHO_OPTIONS="${1}"
	    else
		echo ${ECHO_OPTIONS} "$1" | tee -a ${LOGFILE}
	    fi
	    shift
	done
    fi

    return 0
}

# Initialize the log file.
log_message -init

# Check if HBAnywareSSC install option is passed in
if [ -n "$opt" ];then
    opt=`echo $opt | tr A-Z a-z`
    if [ "$opt" = "ssc" ];then
        SSCInstall=1
    fi
    if [ "$opt" = "upgradekernel" ];then
        kernelInstall=1
    fi
fi

#
# This scripts installs HBAnyware and HBAnywareSSC for Linux. Also
# included our lpfc helper modules and libraries. This script
# also provides kernel upgrade capability
#
                                                                                                                        
# Get environment data
OS=`uname -s`
Arch=`uname -m`
if [ "$Arch" = "i686" ];then
    Arch="i386"
fi

if [ "$OS" = "Linux" ];then
   Kernel_Ver=`uname -r 2>&1 | awk '{ print $1 }' | awk -F. '{ print $1$2 }'`
fi

# init to default value
GCC_Ver="3"

if [ -f /etc/redhat-release ]; then
    rhel_major_version=`cat /etc/redhat-release | awk '{ print $7 }' | awk -F. '{ print $1 }'`

    if [ "$rhel_major_version" -eq 4 ];then
        # is this rhel5 Tikanga release
        rhel5_check=`cat /etc/redhat-release | grep Tikanga`
        if [ -n "$rhel5_check" ];then
           OS_Type="RH5"
           OS_Ver="rhel-5.0"
           OS_Ver_dfc="rhel-5.0"
           GCC_Ver="4"
        else
           OS_Type="RH4"
           OS_Ver="rhel-4.0"
           OS_Ver_dfc="rhel-4.0"
           GCC_Ver="3"
        fi
    else
        OS_Type="RH5"
        OS_Ver="rhel-5.0"
        OS_Ver_dfc="rhel-5.0"
        GCC_Ver="4"
    fi
elif [ -f /etc/SuSE-release ]; then
    sles_major_version=`cat /etc/SuSE-release | grep VERSION | awk '{ print $3 }'`
    if [ "$sles_major_version" -eq 10 ];then
        # is this sles10 release
        OS_Type="SL10"
        OS_Ver="sles-10.0"
        sles_minor_version=`cat /etc/SuSE-release | grep PATCHLEVEL | awk '{ print $3 }'`
        if [ "$sles_minor_version" = "1" ];then
           OS_Ver_dfc="sles-10-sp1"
        else
           OS_Ver_dfc="sles-10.0"
        fi
        GCC_Ver="4"
    else
        OS_Type="SL9"
        OS_Ver="sles-9.0"
        OS_Ver_dfc="sles-9.0"
        GCC_Ver="3"
    fi
else
    echo "ERROR: Cannot determine Linux distribution."
    exit
fi


# This is a Linux install only, if we're not on Linux then stop
if [ "$OS" != "Linux" ];then
    log_message "This installation is for Linux only! Exiting..."
    exit
fi
                                                                                                                        
# Only proceed with SSC install if HBAnyware is installed
if [ $SSCInstall -eq 1 ];then
    Cur_HBA=`rpm -qa | grep HBAnyware | grep -v SSC`
    if [ -z "$Cur_HBA" ];then
        log_message "ERROR: HBAnyware not installed. HBAnyware must be installed before SSC can be installed"
        exit
    fi
fi

# create temporary directory for storing of scripts, to be removed at endof install
mkdir /install_temp
cp ./uninstall /install_temp
# don't install lpfcdfc for rhel5
if [ "$OS_Type" != "RH5" ]; then
   if [ "$OS_Ver_dfc" != "sles-10-sp1" ]; then
      cp ./enterprise_kitfiles/lpfcdfc-install /install_temp
   fi
fi
cd enterprise_kitfiles

# Untar and uncompress tgz file
log_message "Untarring EmlxApps tgz file..."
tar xfz EmlxApps*.tgz
#log_message ""

# Kernel Upgrade
if [ $kernelInstall -eq 1 ];then
     log_message "Upgrading Kernel"
	./lpfcdfc-install -k
    if [ $? -eq 0 ];then
        log_message "Success upgrading kernel."
    else
        log_message "Errors encountered upgrading kernel."
    fi
else 
    if [ $SSCInstall -eq 1 ];then
#      HBAnywareSSC Installation

       # Uninstall any previousely installed HBAnywareSSC
       Cur_HBA=`rpm -qa | grep HBAnywareSSC`
       if [ -n "$Cur_HBA" ];then
           log_message "Uninstalling HBAnywareSSC -- $Cur_HBA -- ..."
           rpm -e "$Cur_HBA"
       fi

       # Verify HBAnyware installed version matches candidate SSC version
       rpm_dir="./${Arch}_${OS_Type}_${GCC_Ver}.XX"
       cd "$rpm_dir"
       hbanyware_version=`rpm -qa | grep HBAnyware | grep -v SSC`
       hbanyware_version=`echo $hbanyware_version | awk -F\- '{ print $2 }'`
       ssc_version=`ls HBAnywareSSC*.rpm | awk -F\- '{ print $2 }'`
       ##echo "ssc version is $ssc_version"
       ##echo "hbanyware_version version is $hbanyware_version"

       if [ "$hbanyware_version" = "$ssc_version" ]; then
           # Install HBAnywareSSC
           rpm -U --nodeps HBAnywareSSC-*.rpm
           cd ..
           log_message ""

           log_message "HBAnywareSSC installation complete."
           log_message ""
       else
           echo "Error: version mismatch detected between installed HBAnyware and candidate SSC versions."
           echo "HBAnyware and HBAnyware SSC versions must match; exiting without installing SSC."
          exit
       fi
    else
       # HBAnyware Installation

       # Make sure this platform is supported
       rpm_dir="./${Arch}_${OS_Type}_${GCC_Ver}.XX"
       if [ ! -d "$rpm_dir" ];then
           log_message "ERROR: $rpm_dir not found"
           log_message "This apps kit does not support this platform"
           exit
       fi

	   # don't install lpfcdfc for rhel5
       if [ "$OS_Type" != "RH5" ]; then
          if [ "$OS_Ver_dfc" != "sles-10-sp1" ]; then
             # Install dfc helper module
             log_message "Installing lpfcdfc helper module..."
             ./lpfcdfc-install -i
             EXITCODE=$?
             if [ ${EXITCODE} -ne 0 ];then
                if [ ${EXITCODE} -eq 10 ];then
                   log_message ""
                   log_message "Success with WARNINGS installing Application Helper"
                   log_message "Module.  Please refer to the following file for more"
                   log_message "information about these warnings:"
                   log_message "   ${LOGFILE}"
                   log_message ""
                else
                   log_message ""
                   log_message "ERROR: Application Helper Module installation failed."
                   log_message ""
                   exit
                fi
             else
	        log_message "Success installing Application Helper Module"
             fi
          fi
       fi

       # Backup existing config files
	   log_message "Back up existing configuration files"
       #rm -f /etc/emulexRMConfig.bak
       #rm -f /etc/emulexRMOptions.bak
       rm -f /etc/emulexDiscConfig.bak
       #if [ -f /etc/emulexRMConfig ]; then
       #    mv -f /etc/emulexRMConfig /etc/emulexRMConfig.bak
       #fi
       #if [ -f /etc/emulexRMOptions ]; then
       #    mv -f /etc/emulexRMOptions /etc/emulexRMOptions.bak
       #fi
       if [ -f /etc/emulexDiscConfig ]; then
           mv -f /etc/emulexDiscConfig /etc/emulexDiscConfig.bak
       fi

       # Uninstall any previous HBAnyware install
       log_message "Scanning for previous HBAnyware installations ..."
       Cur_HBA=`rpm -qa | grep HBAnyware | grep -v SSC`
       if [ -n "$Cur_HBA" ];then
           log_message "Uninstalling HBAnyware -- $Cur_HBA -- ..."
           rpm -e --nodeps "$Cur_HBA"
           log_message ""
       fi

       # Uninstall any previous HBAnywareLite install
       Cur_HBA=`rpm -qa | grep elxlinuxcorekit | grep -v SSC`
       if [ -n "$Cur_HBA" ];then
           echo "Uninstalling elxlinuxcorekit -- $Cur_HBA -- ..."
           rpm -e --nodeps "$Cur_HBA"
           echo ""
       fi
 
       # Uninstall any previous AutoPilot install
       Cur_AP=`rpm -qa | grep AutoPilot`
       if [ -n "$Cur_AP" ];then
           log_message "Uninstalling AutoPilot -- $Cur_AP -- ..."
           rpm -e --nodeps "$Cur_AP"
           log_message ""
       fi
 
       # Uninstall any previous 64 bit DFC library install
       Cur_DFC=`rpm -qa | grep "libdfc-64bit"`
       if [ -n "$Cur_AP" ];then
           log_message "Uninstalling 64 bit DFC library -- $Cur_AP -- ..."
           rpm -e --nodeps "$Cur_AP"
           log_message ""
       fi
 
       # Uninstall any previous DFC library install
       Cur_DFC=`rpm -qa | grep "libdfc-"`
       if [ -n "$Cur_AP" ];then
           log_message "Uninstalling DFC library -- $Cur_AP -- ..."
           rpm -e --nodeps "$Cur_AP"
           log_message ""
       fi
 
       # determine name of DFC library tar file 
       dfc_name_test=`find . -name lpfcutil*`
       if [ -n "$dfc_name_test" ];then
           DFCUTIL_NAME="lpfcutil"
       else
           DFCUTIL_NAME="libdfc"
       fi

       # Install dfc libs and utility
       dfc_test=`find . -name ${DFCUTIL_NAME}*.tgz`
       if [ -n "$dfc_test" ];then
          log_message "Untarring ${DFCUTIL_NAME} tgz file..."
          tar xfz ${DFCUTIL_NAME}*.tgz
       else
          log_message "Untarring ${DFCUTIL_NAME} .tar.gz file..."
          tar xfz ${DFCUTIL_NAME}*.tar.gz
       fi

       # install using "rpm logic" or "tar logic"
       rpm_test=`find ./${DFCUTIL_NAME} -name *.rpm`
       if [ -n "$rpm_test" ];then
          log_message "Installing DFC libraries via RPM ..."
          
          # If ppc64 install 32bit ppc libs also
          if [ "$Arch" = "ppc64" ]; then

              # install 32-bit DFC lib
              rpm -U ./${DFCUTIL_NAME}/ppc/${OS_Ver_dfc}/libdfc-*

              # check for required libraries, 64-bit libnl.so needed for RH5 libdfc
              if [ "$OS_Type" = "RH5" ]; then
                 # test if we should install 64-bit DFC lib
                 ppc64_test=`rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" libnl | grep ppc64`
                 if [ -n "$ppc64_test" ];then
                    rpm -U ./${DFCUTIL_NAME}/ppc64/${OS_Ver_dfc}/libdfc-*
                 else
                    # allow other versions in check
                    libnl_present=`find /usr/lib64 -name libnl.so*`
                    if [ -n "$libnl_present" ];then
                       rpm -U ./${DFCUTIL_NAME}/ppc64/${OS_Ver_dfc}/libdfc-*
                    else
                       log_message "Unable to install 64-bit development kit library due to missing" 
                       log_message "64-bit shared object library: libnl.so"
                       log_message "If 64-bit development kit desired, please install RPM package:"
                       log_message "libnl-1.0-0.10.pre5.4.ppc64 which includes the 64-bit libnl.so."
                       if [ ! -f /usr/sbin/lpfc/dfc ]; then
                          ln -s /usr/sbin/lpfc/dfc32 /usr/sbin/lpfc/dfc
                       fi
                    fi
                 fi
              else
                 if [ "$OS_Ver_dfc" = "sles-10-sp1" ]; then
                    # test if we should install 64-bit DFC lib
                    ppc64_test=`rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" libnl | grep ppc64`
                    if [ -n "$ppc64_test" ];then
                       rpm -U ./${DFCUTIL_NAME}/ppc64/${OS_Ver_dfc}/libdfc-*
                    else
                       # allow other versions in check
                       libnl_present=`find /usr/lib64 -name libnl.so*`
                       if [ -n "$libnl_present" ];then
                          rpm -U ./${DFCUTIL_NAME}/ppc64/${OS_Ver_dfc}/libdfc-*
                       else
                          log_message "Unable to install 64-bit development kit library due to missing" 
                          log_message "64-bit shared object library: libnl.so"
                          log_message "If 64-bit development kit desired, please install RPM package:"
                          log_message "libnl-1.0-0.10.pre5.4.ppc64 (or equivalent) that includes 64-bit libnl.so."
                          if [ ! -f /usr/sbin/lpfc/dfc ]; then
                             ln -s /usr/sbin/lpfc/dfc32 /usr/sbin/lpfc/dfc
                          fi
                       fi
                    fi
                 else
                    rpm -U ./${DFCUTIL_NAME}/ppc64/${OS_Ver_dfc}/libdfc-*
                 fi
              fi
          else
              # Install default architecture libs
              rpm -U ./${DFCUTIL_NAME}/${Arch}/${OS_Ver_dfc}/libdfc-*

              # If amd64 or em64t install 32bit libs also
              if [ "$Arch" = "x86_64" ]; then
                  if [ "$OS_Type" = "SL10" ]; then
                     if [ "$OS_Ver_dfc" = "sles_10.0" ]; then
                         rpm -U ./${DFCUTIL_NAME}/i386/${OS_Ver_dfc}/libdfc-*
                     else
                         # check for required libraries, 32-bit libnl.so needed for libdfc
                         x86_64_test=`rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" libnl | grep i386`
                         if [ -n "$x86_64_test" ];then
                            rpm -U ./${DFCUTIL_NAME}/i386/${OS_Ver_dfc}/libdfc-*
                         else
                            # allow other versions in check
                            libnl_present=`find /usr/lib -name libnl.so*`
                            if [ -n "$libnl_present" ];then
                               rpm -U ./${DFCUTIL_NAME}/i386/${OS_Ver_dfc}/libdfc-*
                            else
                               log_message "Unable to install 32-bit development kit library due to missing" 
                               log_message "32-bit shared object library: libnl.so"
                               log_message "If 32-bit development kit desired, please install RPM package:"
                               log_message "libnl-1.0-0.10.pre5.4.i386 (or equivalent) that includes 32-bit libnl.so."
                               if [ ! -f /usr/sbin/lpfc/dfc ]; then
                                  ln -s /usr/sbin/lpfc/dfc64 /usr/sbin/lpfc/dfc
                               fi
                            fi                            
                         fi
                     fi
                  else
                     if [ "$OS_Type" = "RH5" ]; then
                         # check for required libraries, 32-bit libnl.so needed for libdfc
                         x86_64_test=`rpm -q --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" libnl | grep i386`
                         if [ -n "$x86_64_test" ];then
                            rpm -U ./${DFCUTIL_NAME}/i386/${OS_Ver_dfc}/libdfc-*
                         else
                            # allow other versions in check
                            libnl_present=`find /usr/lib -name libnl.so*`
                            if [ -n "$libnl_present" ];then
                               rpm -U ./${DFCUTIL_NAME}/i386/${OS_Ver_dfc}/libdfc-*
                            else
                               log_message "Unable to install 32-bit development kit library due to missing" 
                               log_message "32-bit shared object library: libnl.so"
                               log_message "If 32-bit development kit desired, please install RPM package:"
                               log_message "libnl-1.0-0.10.pre5.4.i386 (or equivalent) that includes 32-bit libnl.so."
                               if [ ! -f /usr/sbin/lpfc/dfc ]; then
                                  ln -s /usr/sbin/lpfc/dfc64 /usr/sbin/lpfc/dfc
                               fi 
                            fi                              
                         fi
                     else
                         rpm -U ./${DFCUTIL_NAME}/i386/${OS_Ver_dfc}/libdfc-*
                     fi
                  fi
              fi
          fi
       else
          log_message "Installing DFC libraries via tar copy ..."
          if [ ! -d /usr/sbin/lpfc ];then
              mkdir /usr/sbin/lpfc
          fi
          # this will copy DFC test utility
          if [ "$Arch" = "ppc64" ]; then
              cp -f ./${DFCUTIL_NAME}/ppc/${OS_Ver_dfc}/dfc /usr/sbin/lpfc
          else
              # If amd64 then install 64bit libs also
              if [ "$Arch" = "x86_64" ]; then
                  cp -f ./${DFCUTIL_NAME}/${Arch}/${OS_Ver_dfc}/dfc /usr/sbin/lpfc
              else
                  cp -f ./${DFCUTIL_NAME}/${Arch}/${OS_Ver_dfc}/dfc /usr/sbin/lpfc
              fi
          fi
       fi

       # Copy lun_scan script to /usr/sbin/lpfc directory
       if [ -f "./scripts/lun_scan" ]; then
           cp -f ./scripts/lun_scan /usr/sbin/lpfc
       else
           if [ -f "./lun_scan" ]; then
               cp -f ./lun_scan /usr/sbin/lpfc
           fi
       fi

       # Install multipulse library
       mpl_test=`find . -name libmpl*.tgz`
       if [ -n "$mpl_test" ];then
          echo "Untarring libmpl tgz file..."
          tar xfz libmpl*.tgz
       else
          mpl_test=`find . -name libmpl*.tar.gz`
          if [ -n "$mpl_test" ];then
             echo "Untarring libmpl .tar.gz file..."
             tar xfz libmpl*.tar.gz
          else
             echo "Error Untarring libmpl.tar.gz file: file not found"
          fi
       fi

       # this will copy multipulse libraries and DFC also (if "tar installed")
       if [ "$Arch" = "ppc64" ]; then
           # check for required libraries, 64-bit libnl.so needed for RH5 libdfc
           if [ "$OS_Type" = "RH5" ]; then	
                # multipulse libs only
           	    cp -f ./lpfcutil/ppc/${OS_Ver}/lib*.so* /usr/lib
           else
                if [ "$OS_Type" = "SL10" ]; then
                    # multipulse libs only
                    cp -f ./lpfcutil/ppc/${OS_Ver}/lib*.so* /usr/lib
                else
                    # dfc and multipulse libs
                    cp -f ./lpfcutil/ppc/${OS_Ver}/lib*.so* /usr/lib
                    cp -f ./lpfcutil/ppc64/${OS_Ver}/lib*.so* /usr/lib64
                fi
           fi
       else
           # If amd64 then install 64bit libs also
           if [ "$Arch" = "x86_64" ]; then
               cp -f ./lpfcutil/i386/${OS_Ver}/lib*.so* /usr/lib
               cp -f ./lpfcutil/${Arch}/${OS_Ver}/lib*.so* /usr/lib64
           else
               cp -f ./lpfcutil/${Arch}/${OS_Ver}/lib*.so* /usr/lib
           fi
       fi

       # Install HBAAPI libs
       log_message "Untarring hbaapi libs tgz file..."
       tar xfz hbaapi*.tgz
       if [ "$Arch" = "i386" ]; then
           cp -f ./hbaapi/${Arch}/32bit/lib* /usr/lib
       fi
       if [ "$Arch" = "ia64" ]; then
           cp -f ./hbaapi/${Arch}/64bit/lib* /usr/lib
       fi
       if [ "$Arch" = "ppc64" ]; then
           cp -f ./hbaapi/${Arch}/32bit/lib* /usr/lib
           if [ "$Kernel_Ver" = "26" ]; then
               cp -f ./hbaapi/${Arch}/64bit/lib* /usr/lib64
           else
               cp -f ./hbaapi/${Arch}/64bit/${OS_Ver}/lib* /usr/lib64
	       fi
       fi
       if [ "$Arch" = "x86_64" ]; then
           cp -f ./hbaapi/i386/32bit/lib* /usr/lib
           cp -f ./hbaapi/amd64/64bit/lib* /usr/lib64
       fi


       # Install lputil utility
       log_message "Untarring lputil tgz file..."
       tar xfz lputil*.tgz
       if [ -f /usr/sbin/lpfc ];then
           rm -f /usr/sbin/lpfc
       fi
       if [ ! -d /usr/sbin/lpfc ];then
           mkdir /usr/sbin/lpfc
       fi

#       if [ "$Arch" = "x86_64" ]; then
#            cp -f ./lputil/i386/lputil* /usr/sbin/lpfc
#	   else
             cp -f ./lputil/${Arch}/lputil* /usr/sbin/lpfc
#	   fi
       chmod +x /usr/sbin/lpfc/lputil*


       # Install HBAnyware
       cd "$rpm_dir"
       rpm -U HBAnyware-*.rpm
       cd ..
#       log_message ""

       # Create Well-Known location for uninstall_hbanyware script
       if [ ! -d /usr/sbin/hbanyware/scripts ];then
           mkdir /usr/sbin/hbanyware/scripts
       fi
       cp -f /install_temp/uninstall /usr/sbin/hbanyware/scripts/uninstall_hbanyware
           # don't install lpfcdfc for rhel5
       if [ "$OS_Type" != "RH5" ]; then
          if [ "$OS_Ver_dfc" != "sles-10-sp1" ]; then
            cp -f /install_temp/lpfcdfc-install /usr/sbin/hbanyware/scripts/lpfcdfc-install
          fi
       fi
       rm -rf /install_temp

       # make directory for semaphore file locks
       if [ ! -d /usr/sbin/hbanyware/misc ];then
           mkdir /usr/sbin/hbanyware/misc
       fi

       # Install IBM director support files 
       if [ -d /opt/ibm/director/classes/doc/en/common ];then
           cp ./director/emulex.gif /opt/ibm/director/classes/doc/en/common
           log_message "Copying Emulex GIF file into IBM director directory"
       fi
       if [ -d /opt/ibm/director/classes/extensions ];then
           cp ./director/HBAnyware_unix.CMDExt /opt/ibm/director/classes/extensions/HBAnyware.CMDExt
           log_message "Copying Emulex HBAnyware Command file into IBM director directory"
       fi

       # Install JRE
       cur_dir=`pwd`
       jre_dir="./jre_${Arch}"
       if [ ! -d "$jre_dir" ];then
           log_message "ERROR: JRE dir $jre_dir not found. HBAnyware local JRE can not be installed"
           exit
       fi
       if [ ! -d /usr/sbin/hbanyware/jre ];then
           mkdir /usr/sbin/hbanyware/jre
       fi
       cd /usr/sbin/hbanyware/jre
       log_message "Untarring HBAnyware local jre..."
       tar xfz ${cur_dir}/${jre_dir}/jre_hbanyware.tgz
       if [ "$Arch" = "ppc64" ]; then
          if [ "$OS_Type" = "RH5" ]; then
             which chcon >/dev/null 2>&1
             if [ $? -eq 0 ]; then
                if [ -x /usr/sbin/selinuxenabled ]; then
                   /usr/sbin/selinuxenabled
                   if [ $? -eq 0 ]; then
                      chcon -t texrel_shlib_t /usr/sbin/hbanyware/jre/bin/j9vm/*.so
                      chcon -t texrel_shlib_t /usr/sbin/hbanyware/jre/bin/classic/*.so
                      chcon -t texrel_shlib_t /usr/sbin/hbanyware/jre/lib/ppc/*.so
                      chcon -t texrel_shlib_t /usr/sbin/hbanyware/jre/bin/classic/*.so
                      chcon -t texrel_shlib_t /usr/sbin/hbanyware/jre/bin/xawt/*.so
                      chcon -t texrel_shlib_t /usr/sbin/hbanyware/jre/bin/*.so
                   fi
                fi
             fi
          fi
       fi
       cd "$cur_dir"
#       log_message ""

       # restore any pre-existing config files
       log_message "Restoring pre-existing configuration files..."
       #if [ -f /etc/emulexRMConfig.bak ]; then
       #    mv -f /etc/emulexRMConfig.bak /etc/emulexRMConfig
       #fi
       #if [ -f /etc/emulexRMOptions.bak ]; then
       #    mv -f /etc/emulexRMOptions.bak /etc/emulexRMOptions
       #fi
       if [ -f /etc/emulexDiscConfig.bak ]; then
           mv -f /etc/emulexDiscConfig.bak /etc/emulexDiscConfig
       fi

       # obtain user selections for remote management
       cd /usr/sbin/hbanyware
       ./set_operating_mode 45
       cd "$cur_dir"

       # remove script that changes operating mode if installer selects this option
       no_mode_change=`cat /etc/emulexDiscConfig | grep ClientOperationMode | grep locked`
	   if [ -n "$no_mode_change" ];then
	      rm -f /usr/sbin/hbanyware/set_operating_mode
	   fi
       log_message ""
       log_message "HBAnyware installation complete."
       log_message ""
       log_message "Type:   /usr/sbin/hbanyware/hbanyware"
       log_message "to run HBAnyware GUI client."
       log_message ""
	fi
fi


# Clean up
#log_message "Cleaning up..."
cd "$cur_dir"
rm -rf ./*.XX
rm -rf ./jre_*
rm -rf ./etc
rm -rf ./director
rm -rf lputil
rm -rf hbaapi
rm -rf lpfcutil
rm -rf libdfc
#log_message ""

cd ..

